﻿using Fish.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Fish.Controllers;

namespace Fish.DAL
{
    public class FishInitializer : System.Data.Entity.DropCreateDatabaseAlways<FishContext>
    {
        protected override void Seed(FishContext context)
        {
            AccountController ac = new AccountController();
            string salt = ac.CreateSalt(16); string hashedPass = ac.GenerateSaltedHash("loozer", salt);
            List<string> MyTasks = new List<string>();
            MyTasks.Add("Geeb el akel"); MyTasks.Add("Ta3ala fe ma3adak"); MyTasks.Add("Rawa7 ba2a");

            var users = new List<Users>
            {

                new Users{Username="OmarF", Password=hashedPass, Salt=salt, DateOfBirth=DateTime.Parse("2005-09-01"), Email="omar.fouda8@gmail.com"},
                new Users{Username="LamaA", Password=hashedPass, Salt=salt, DateOfBirth=DateTime.Parse("1990-09-01"), Email="lama.ashraf@gmail.com"}
            };


            var events = new List<Events>
            {
                new Events{Name="Launch", TemplatesID=1, PrivacyType=1},
            };

            var eventUserRelations = new List<EventUserRelations>
            {
                new EventUserRelations{UsersID=1, EventsID=1, IsAdmin=true, AttendingStatus=0},
                new EventUserRelations{UsersID=2, EventsID=1, IsAdmin=true, AttendingStatus=0},
            };
            
            var templates = new List<Templates>
            {
                new Templates{Name="Birthday", Tabs=new List<tabNumber>{new tabNumber(){number=0},new tabNumber(){number=1},new tabNumber(){number=3}}, isPublic = true},
                new Templates{Name="Dish Party", Tabs=new List<tabNumber>{new tabNumber(){number=0},new tabNumber(){number=1},new tabNumber(){number=2},new tabNumber(){number=3}}, isPublic = true},
                new Templates{Name="Outing", Tabs=new List<tabNumber>{new tabNumber(){number=0},new tabNumber(){number=2},new tabNumber(){number=3}}, isPublic = true}
            };

            var eventInf = new List<EventInfo>{
                new EventInfo{EventsID=1, Description="Newest Event", MaximumGuests = 3, StartDate = DateTime.Parse("2009-09-01"),EndDate = DateTime.Parse("2009-09-01")}
            };

            users.ForEach(s => context.Users.Add(s));
            context.SaveChanges();

            templates.ForEach(s => context.Templates.Add(s));
            context.SaveChanges();

            events.ForEach(s => context.Events.Add(s));
            context.SaveChanges();

            eventUserRelations.ForEach(s => context.EventUserRelations.Add(s));
            context.SaveChanges();

        //    System.Diagnostics.Debug.WriteLine("Tasks: " + context.EventUserRelations.First().Tasks.First());

            eventInf.ForEach(s => context.EventInfoes.Add(s));
            context.SaveChanges();

        }
    }
}